#coding=utf-8
from stockdb.misc import *
from sqlalchemy.exceptions import InvalidRequestError

class TDFilter(object):
    def __init__(self, tds):
        self.tds = tds
        
    def filter_by(self, func, *args):
        r = []
        
        for td in self.tds:
        
            if func(td, *args):
                r.append(td)
                
        return TDFilter(r)
        
    def all(self):
        return self.tds
         
def tdattr_filter(td, attr, a, b):
    if hasattr(td, attr):
        v = getattr(td, attr)
    else:
        p = td.price
        v = getattr(p, attr)
    if v >= a and v <= b :return True
    return False

def st_filter(td):
    s = td.fins
    if s.name.upper().find('S') != -1:
        return False
    return True




    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
